package gdut.imis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import gdut.imis.Utils.Result;
import gdut.imis.domain.EmploymentFile;
import gdut.imis.enums.Status;
import gdut.imis.mapper.EmploymentFileMapper;
import gdut.imis.service.EmploymentFileService;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description
 * @Author JiaFu
 * @Date 2023/4/7 21:34
 */
@Service
public class EmploymentFileServiceImpl extends ServiceImpl<EmploymentFileMapper, EmploymentFile> implements EmploymentFileService {

    /***
     * 新增就业档案
     * @param: employmentFile
     * @return Result
     */
    @Override
    public Result addEmploymentFile(EmploymentFile employmentFile) {
        if (Objects.isNull(employmentFile)) {
            return Result.errorWithArgs(Status.REQUEST_PARAMS_NOT_VALID_ERROR, "employmentFile");
        }
        boolean flag = this.save(employmentFile);
        if (flag) {
            return Result.success();
        }
        return Result.errorWithArgs(Status.FAILED, "新增就业档案失败");
    }


    /***
     * 根据学生id查询学生就业信息
     * @param: studentId
     * @return Result
     */
    @Override
    public Result getEmploymentByStuId(Long studentId) {
        LambdaQueryWrapper<EmploymentFile> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EmploymentFile::getStudentId, studentId);
        EmploymentFile employmentFile = this.getOne(queryWrapper);
        if (Objects.isNull(employmentFile)) {
            return Result.errorWithArgs(Status.FAILED, "没有查询到该学生的就业档案");
        }
        return Result.success(employmentFile);
    }
}
